#include "engine.h"
#include "random.h"

unsigned rand_seed=1;

int srand()
{
	unsigned int hi,lo;

	hi = 16807 * (rand_seed >> 16);
	lo = 16807 * (rand_seed & 0xFFFF);
	lo += (hi & 0x7FFF) << 16;
	lo += hi >> 15;
	if (lo > 2147483647)
		lo -= 2147483647;
	rand_seed = lo;
	return rand_seed;
}

int srand(int minval, int maxval)
{
	return minval+srand()%(maxval+1-minval);
}
float sfrand(float minval, float maxval)
{
	return minval+((float)(srand() & 0xffff))/65535.0f*(maxval-minval);
}


int get_rand_seed()
{
	return rand_seed;
}

void set_rand_seed(int seed)
{
	rand_seed=seed;
}
